#include "GlobalPrec.h"
#include <stdio.h>

void GameLayerConfigMgr::Init(GameLayerConfigFileLoader* fileloader,GameLayerStrategy& Strategy)
{
	mFileLoader=fileloader;
	Strategy.RegistLayer(&mElemCreator);
	CSList<CSString> LayerFileLst;
	Strategy.LoadLayerFile(&LayerFileLst);
	for(CSList<CSString>::iterator iter=LayerFileLst.Begin();iter!=LayerFileLst.End();++iter)
	{
		LoadFile(*iter);
	}
}

GameLayer* GameLayerConfigMgr::CreateLayer(CSString classname)
{
	if(!mLayerConfig.Found(classname))
		return 0;
	GameLayerConfigLayer* config = mLayerConfig.FindRef(classname);
	if(!config)
		return 0;
	return (GameLayer*)config->Create();
}

void GameLayerConfigMgr::MTCreateLayer(CSString classname,CCNode* parent)
{
	if(!mLayerConfig.Found(classname))
		return ;
	GameLayerConfigLayer* config = mLayerConfig.FindRef(classname);
	if(!config)
		return ;
	config->MTLoad(parent);
}

void GameLayerConfigMgr::LoadFile(CSString filename)
{
	mFileLoader->LoadFile(filename,mLayerConfig);
}

